package org.skyfree.ghyll.tcard.action;

import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.graphics.Image;
import org.skyfree.ghyll.tcard.core.IResourceChangeEvent;
import org.skyfree.ghyll.tcard.core.ITWorkpiece;
import org.skyfree.ghyll.tcard.core.ResourceChangeEvent;
import org.skyfree.ghyll.tcard.core.TCardCore;

public class MoveProgressMenuItemAction extends AbstractMenuItemAction {

	public MoveProgressMenuItemAction(int style, String text, int Accelerator,
			Image image,TreeViewer treeViewer) {
		super(style, text, Accelerator, image,treeViewer);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void execute(Object source) throws Exception 
	{
		ITWorkpiece wp = (ITWorkpiece)this.item.getData();
		wp.move2Progress();
		ResourceChangeEvent event = new ResourceChangeEvent(IResourceChangeEvent.Type_Progress,
				IResourceChangeEvent.OP_ADD,wp);
		TCardCore.getDefault().fireResourceChangedEvent(event);
	}

	@Override
	public boolean isEnable() 
	{
		Object data = this.item.getData();
		if(data instanceof ITWorkpiece)
		{
			ITWorkpiece select = (ITWorkpiece)data;
			if(select.isInProgress())return false;
			else return true;
		}
		else return false;
	}

}
